package com.lyq.homework.planA;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;


public class NumSortingDiverA {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Path inputPath=new Path("D:\\MR\\in\\file");
        Path outputPath=new Path("D:\\MR\\out\\file");

        Configuration conf =new Configuration();

        Job job = Job.getInstance(conf,"NumSortingDiver");

        job.setJarByClass(NumSortingDiverA.class);
        job.setMapperClass(NumSortingAMapper.class);
        job.setReducerClass(NumSortingAReduce.class);

        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(NullWritable.class);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);




        //保证输出目录不存在
        FileSystem fs=FileSystem.get(conf);
        if (fs.exists(outputPath)) {
            fs.delete(outputPath, true);
        }

        //读取的数据路径
        FileInputFormat.setInputPaths(job, inputPath);
        FileOutputFormat.setOutputPath(job, outputPath);

        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
